import {Directive, Input, OnInit} from '@angular/core';
import {GnTreeDirective} from 'geminis-ng';

@Directive({
  selector: '[everydata-category-tree]',
})
export class CategoryTreeDirective implements OnInit {

  @Input() showRoot = false;

  constructor(private tree: GnTreeDirective) {
  }

  ngOnInit(): void {
    this.tree.url = '/api/everydata/categories/children/';
    this.tree.valueField = 'id';
    this.tree.textField = 'name';
    if (this.showRoot) {
      this.tree.rootNode = {id: null, name: '数据分类', pathId: '/'};
    }
  }

}
